package com.burst.reptile.modular.zp.service.impl;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.burst.reptile.common.exception.CustomException;
import com.burst.reptile.common.utils.ToolUtil;
import com.burst.reptile.modular.zp.entity.ZpFeedback;
import com.burst.reptile.modular.zp.mapper.ZpFeedbackMapper;
import com.burst.reptile.modular.zp.service.IZpFeedbackService;

import cn.hutool.core.util.StrUtil;

/**
 * <p>
 * 意见反馈 服务实现类
 * </p>
 *
 * @author wujin
 * @since 2020-07-11
 */
@Service
public class ZpFeedbackServiceImpl extends ServiceImpl<ZpFeedbackMapper, ZpFeedback> implements IZpFeedbackService {

	@Override
	public int add(ZpFeedback feedback) {
		return this.baseMapper.insert(feedback);
	}

	@Override
	public Page<ZpFeedback> pageList(Page<ZpFeedback> page, ZpFeedback feedback) {
		QueryWrapper<ZpFeedback> queryWrapper = new QueryWrapper<>();
		String ftype = feedback.getFtype();
		String fstatus = feedback.getFstatus();
		if(StrUtil.isNotEmpty(ftype)) {
			queryWrapper.eq("ftype", ftype);
		}
		if(StrUtil.isNotEmpty(fstatus)) {
			queryWrapper.eq("fstatus", fstatus);
		}
		queryWrapper.orderByDesc("create_time");
		return this.page(page, queryWrapper);
	}

	@Override
	public int receipt(ZpFeedback feedback) {
		Integer fid = feedback.getFid();
		ZpFeedback byId = this.getById(fid);
		if(ToolUtil.isEmpty(byId)) {
			throw new CustomException("处理的资源不存在");
		}
		byId.setFresult(feedback.getFresult());
		byId.setFstatus("2");
		int updateById = this.baseMapper.updateById(byId);
		// 发送短信 TODO
		return updateById;
	}

}
